package com.kang.service.serviceImpl;

import com.kang.mapper.UsersMapper;
import com.kang.pojo.Users;
import com.kang.service.UsersService;
import com.kang.utils.EmailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

/**
 * @Author 吃三明治派对中的康康
 * @Date 2022/4/30 15:09
 * @Version 1.0
 */
@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;


    @Override
    public Users loginUser(String username, String password) {

        Users user;
        if(EmailUtils.isEmail(username)){
            user = usersMapper.searchByEmailAndPasswordUsers(username,password);
        }else{
            user = usersMapper.searchByMobileAndPasswordUsers(username, password);
        }

        return user;
    }

    @Override
    public int regUser(Users user, String reword) {
        int insert = 0;
        if(user.getEmail().contains("@")
                && user.getPassword() != null
                && user.getMobile()   != null
                && user.getUsername() != null
                && user.getPassword().equals(reword)) {
            Date date = new Date();
            user.setRegDate(date.toString());
            user.setFlag(1);
            insert = usersMapper.insert(user);
        }
        return insert;
    }

    @Override
    public Users researchUserById(long id) {
        return usersMapper.selectByPrimaryKey(id);
    }
}
